package icu.groot.alan.util;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.*;

public class MergeStrategy extends AbstractMergeStrategy {
    private List<String> departments = null;
    public MergeStrategy(List<String> departments) {
        this.departments = departments;
    }

    // 每行每列都会进入，绝对不要在这写循环
    @Override
    protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
        //合并 sheet.addMergedRegionUnsafe(new CellRangeAddress(startRow, endRow, startCol, endCol));
        System.out.println(cell.getStringCellValue());
        if (departments.contains(cell.getStringCellValue())){
            sheet.addMergedRegionUnsafe(new CellRangeAddress(cell.getRowIndex(), cell.getRowIndex(), cell.getColumnIndex(), cell.getColumnIndex() + 2));
        }

    }
}
